<?php

namespace app\api\controller;

use app\api\model\HelpCategory;
use app\api\model\HelpQuestion;

class Help extends Common
{
    public function category()
    {
        $data = HelpCategory::all(function($query){
            $query->field('id, title')->where(['sys_channel'=>['in', [0, getenv('APP_CHANNEL')]], 'is_hidden' => 0, 'id'=>['not in', [7,8]]])->order('sort desc, id asc');
        });

        return $this->pass($data);
    }

    public function question()
    {
        $where = ['sys_channel'=>['in', [0, getenv('APP_CHANNEL')]]];

        if (isset($this->params['cid'])) {
            $where['cid'] = $this->params['cid'];
        }

        if (isset($this->params['is_hot'])) {
            $where['is_hot'] = 1;
        }

        $data = HelpQuestion::where($where)->field('id, title, content')->order('sort desc, id asc')->select();

        foreach ($data as $key => $item) {
            $data[$key]['content'] = out_content($item['content']);
        }

        return $this->pass($data);
    }
}
